import React from 'react';
import {Row, Col, Button} from 'antd';
import MyPatientButtons from './myPatientButtons';
import MyPatientSearch from './myPatientSearch';
import MyPatientTable from './myPatientTable';
import MyPatientDetail from './myPatientDetail';
export default class myPatient extends React.Component {
    constructor (props) {
        super(props);
        this.state = {
            detaildisplay: [24, 0],
            showEditor: false,
            showForm: false,
            selectPtInfo: []
        };
    }
    state = {
        query: []
    };
    componentWillReceiveProps (prop) {
        if (prop.refresh !== this.props.refresh) {
            this.setState({detaildisplay: [24, 0]});
        }
    }
    onRowClick(type, rowData) {
        if (type !== "Close") {
            this.setState({detaildisplay: [15, 9], selectPtInfo: rowData});
        } else {
            this.setState({detaildisplay: [24, 0]});
        }
    }
    onButtonsClick(action, args) {
        switch (action) {
        case "showNewMyPatient":
            this.props.showPE({isNew: true});
            break;
        case "showMyPatientEdit":
            this.props.showPE(args);
            break;
        case "onOk":
            this.setState({showEditor: false});
            break;
        case "onCancel":
            this.setState({showEditor: false});
            break;
        }
    }

    doSearch = (vals) => {
        this.setState({query: vals});
    };
    render() {
        return (
            <div>
                <Row>
                    <Col span={this.state.detaildisplay[0]}>
                        <div className="nav left table">
                            <div className="col middle">
                                <MyPatientSearch doSearch={this.doSearch}/>
                                {
                                    MyPatientButtons.map(({text, icon, action}, index) => (
                                        <Button
                                            key={index}
                                            onClick={() => this.onButtonsClick(action)}
                                        >
                                            {text}
                                        </Button>
                                    ))
                                }
                            </div>
                        </div>
                        <div>
                            <MyPatientTable
                                onRowClick={this.onRowClick.bind(this)}
                                showPE={this.onButtonsClick.bind(this)}
                                refresh={this.props.refresh}
                                query={this.state.query}
                            />
                            {/*<div className="w100 padding-t">
                                <Table
                                    columns={columns}
                                    dataSource={dataSource}
                                    {...this.props}
                                    onRowClick={this.onRowClick.bind(this)}
                                />
                            </div>*/}
                        </div>
                    </Col>
                    <Col
                        span={this.state.detaildisplay[1]}
                        style={{
                            backgroundColor: "#e5e5f1",
                            borderRadius: '5px',
                            height: "600px",
                            borderLeft: "solid 2px gray",
                            paddingLeft: "5px"
                        }}
                    >
                        <h4><i className="iconfont icon-guanbi" onClick={() => this.onRowClick("Close")}/> 挂号信息</h4>
                        <MyPatientDetail visitInfo={this.state.selectPtInfo}/>
                    </Col>
                </Row>
            </div>
        );
    }
}
